<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<button id="btn">发送ajax请求</button>

<script>
    let btn = document.getElementById("btn");

    function jsonp(options) {

        let callBackName = "wangcai";

        window[callBackName] = function (data) {
            if (data != null) {
                options.success(data)
            } else {
                options.fail()
            }
        }

        let url = options.url + "?callBack=" + callBackName
        let scriptEle = document.createElement("script");
        scriptEle.src = url;
        document.body.append(scriptEle)
    }

    btn.onclick = function () {
        jsonp({
            url: "http://localhost:3000/",
            success: function (data) {
                console.log("data:", data);
            },
            fail: function (err) {
                console.log("数据请求失败了");
            }
        })
    }
</script>